//格式化时间
//dateTime：时间戳
function getFormtTime(dateTime,flag) {
    if(dateTime != null ) {
        //若传入的dateTime为字符串类型，需要进行转换成数值，若不是无需下面注释代码
        var time = parseInt(dateTime)
        var date = new Date(time);
        //获取年份
        var YY = date.getFullYear();
        //获取月份
        var MM = (date.getMonth() + 1 < 10 ? '0'+(date.getMonth() + 1) : date.getMonth() + 1);
        //获取日期
        var DD = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate());
        if(flag) { //flag为true，显示时分秒格式
            //获取小时
            var hh = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours());
            //获取分
            var mm = (date.getMinutes() < 10 ? '0'+date.getMinutes() : date.getMinutes());
            ///获取秒
            var ss = (date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds());
            //返回时间格式： 2020-11-09 13:14:52
            return YY + '-' + MM + '-' + DD + ' ' + hh + ':' + mm + ':' + ss;
        } else {
            //返回时间格式： 2020-11-09
            return YY + '-' + MM + '-' + DD;
        }
    } else {
        return "";
    }
}
$.ajax({
    type:"post",
    url:"/orde/PageOrde",
    data:{},
    dataType:"json",
    success:function(r) {
        if (r.data != null) {
            var t="<tr>\n" +
                "          <th>序号</th>\n" +
                "          <th>订单编号</th>\n" +
                "          <th>客户姓名</th>\n" +
                "          <th>联系电话</th>\n" +
                "          <th>订购时间</th>\n" +
                "          <th>金额</th>\n" +
                "          <th>操作人</th>\n" +
                "          <th>审核状态</th>\n" +
                "          <th>审核人</th>\n" +
                "          <th>审核时间</th>\n" +
                "          <th>操作</th>\n" +
                "        </tr>"
            for (var i=0;i<r.data.length;i++){
                if (r.data[i].status=="0"){
                    t += "<tr> <td>" + r.data[i].rownum + "</td><td>" + r.data[i].orderid + "</td><td>" + r.data[i].custom.customname + "</td><td>" +r.data[i].custom.telephone+ "</td><td>"+getFormtTime(r.data[i].ordertime,false)+"</td><td>"+r.data[i].ordermoney+"</td><td>"+r.data[i].users1.uname+"</td><td>未审核</td><td>"+r.data[i].users2.uname+"</td><td>"+getFormtTime(r.data[i].chectime,false)+"</td><td>\n" +
                        "          \t<a href=\"javascript:void(0)\" class=\"tablelink\">查看详情</a>\n" +
                        "            <a href=\"javascript:void(0)\" class=\"tablelink\">修改</a>\n" +
                        "            <a href='javascript:void(0);' class='tablelink' onclick='deltipOpen()'>删除</a>\n" +
                        "            <a href='javascript:void(0);' class='tablelink' onclick='examinetipOpen()'>提交审核</a>\n" +
                        "          </td></tr>"
                }else if(r.data[i].status=="1"){
                    t += "<tr> <td>" + r.data[i].rownum + "</td><td>" + r.data[i].orderid + "</td><td>" + r.data[i].custom.customname + "</td><td>" +r.data[i].custom.telephone+ "</td><td>"+getFormtTime(r.data[i].ordertime,false)+"</td><td>"+r.data[i].ordermoney+"</td><td>"+r.data[i].users1.uname+"</td><td>审核中</td><td>"+r.data[i].users2.uname+"</td><td>"+getFormtTime(r.data[i].chectime,false)+"</td><td>\n" +
                        "          \t<a href=\"javascript:void(0)\" class=\"tablelink\">查看详情</a>\n" +
                        "          </td></tr>"
                }else if(r.data[i].status=="2"){
                    t += "<tr> <td>" + r.data[i].rownum + "</td><td>" + r.data[i].orderid + "</td><td>" + r.data[i].custom.customname + "</td><td>" +r.data[i].custom.telephone+ "</td><td>"+getFormtTime(r.data[i].ordertime,false)+"</td><td>"+r.data[i].ordermoney+"</td><td>"+r.data[i].users1.uname+"</td><td>审核通过</td><td>"+r.data[i].users2.uname+"</td><td>"+getFormtTime(r.data[i].chectime,false)+"</td><td>\n" +
                        "          \t<a href=\"javascript:void(0)\" class=\"tablelink\">查看详情</a>\n" +
                        "            <a href='../../storage/delivery/deliveryView.html' class='tablelink'>出库详情</a>\n" +
                        "          </td></tr>"
                }else if(r.data[i].status=="3"){
                    t += "<tr> <td>" + r.data[i].rownum + "</td><td>" + r.data[i].orderid + "</td><td>" + r.data[i].custom.customname + "</td><td>" +r.data[i].custom.telephone+ "</td><td>"+getFormtTime(r.data[i].ordertime,false)+"</td><td>"+r.data[i].ordermoney+"</td><td>"+r.data[i].users1.uname+"</td><td>审核不通过</td><td>"+r.data[i].users2.uname+"</td><td>"+getFormtTime(r.data[i].chectime,false)+"</td><td>\n" +
                        "            <a href=\"javascript:void(0)\" class=\"tablelink\">修改</a>\n" +
                        "            <a href='javascript:void(0);' class='tablelink' onclick='examinetipOpen()'>提交审核</a>\n" +
                        "          </td></tr>"
                }
            }
            $(".tablelist").html(t)
            // var pagenum = document.getElementById("pagenum");
            $("#pagenum").html(r.pageNum)
            // var totalrows = document.getElementById("totalrows");
            // totalrows.innerHTML=r.totalRows
            $("#totalrows").html(r.totalRows)

            $(".tablelink").click(function() {

                var text = $(this).text();
                var orderid = $(this).parents("tr")[0].children[0].innerHTML
                if (text == "查看详情") {
                    window.location.href = "/orde/queryOneOrde/" + orderid
                } else if (text == "修改") {
                    window.location.href = "/orde/updateMarketCustom/" + orderid
                } else if (text == "删除") {

                } else if (text == "提交审核") {

                } else if (text == "出库详情") {

                }
            })

            $("#shangyiye").click(function () {
                if (pagenum.innerHTML > 1) {
                    pagenum.innerHTML = Number(pagenum.innerHTML) - 1;
                } else {
                    alert("已经是第一页了")
                }

                var n = pagenum.innerHTML
                if (n >= 1) {
                    $.ajax({
                        type: "post",
                        url: "/orde/PageOrde",
                        data: {pageNum: n},
                        dataType: "json",
                        success: function (r) {
                            var t="<tr>\n" +
                                "          <th>序号</th>\n" +
                                "          <th>订单编号</th>\n" +
                                "          <th>客户姓名</th>\n" +
                                "          <th>联系电话</th>\n" +
                                "          <th>订购时间</th>\n" +
                                "          <th>金额</th>\n" +
                                "          <th>操作人</th>\n" +
                                "          <th>审核状态</th>\n" +
                                "          <th>审核人</th>\n" +
                                "          <th>审核时间</th>\n" +
                                "          <th>操作</th>\n" +
                                "        </tr>"
                            for (var i=0;i<r.data.length;i++){
                                if (r.data[i].status=="0"){
                                    t += "<tr> <td>" + r.data[i].rownum + "</td><td>" + r.data[i].orderid + "</td><td>" + r.data[i].custom.customname + "</td><td>" +r.data[i].custom.telephone+ "</td><td>"+getFormtTime(r.data[i].ordertime,false)+"</td><td>"+r.data[i].ordermoney+"</td><td>"+r.data[i].users1.uname+"</td><td>未审核</td><td>"+r.data[i].users2.uname+"</td><td>"+getFormtTime(r.data[i].chectime,false)+"</td><td>\n" +
                                        "          \t<a href=\"javascript:void(0)\" class=\"tablelink\">查看详情</a>\n" +
                                        "            <a href=\"javascript:void(0)\" class=\"tablelink\">修改</a>\n" +
                                        "            <a href='javascript:void(0);' class='tablelink' onclick='deltipOpen()'>删除</a>\n" +
                                        "            <a href='javascript:void(0);' class='tablelink' onclick='examinetipOpen()'>提交审核</a>\n" +
                                        "          </td></tr>"
                                }else if(r.data[i].status=="1"){
                                    t += "<tr> <td>" + r.data[i].rownum + "</td><td>" + r.data[i].orderid + "</td><td>" + r.data[i].custom.customname + "</td><td>" +r.data[i].custom.telephone+ "</td><td>"+getFormtTime(r.data[i].ordertime,false)+"</td><td>"+r.data[i].ordermoney+"</td><td>"+r.data[i].users1.uname+"</td><td>审核中</td><td>"+r.data[i].users2.uname+"</td><td>"+getFormtTime(r.data[i].chectime,false)+"</td><td>\n" +
                                        "          \t<a href=\"javascript:void(0)\" class=\"tablelink\">查看详情</a>\n" +
                                        "          </td></tr>"
                                }else if(r.data[i].status=="2"){
                                    t += "<tr> <td>" + r.data[i].rownum + "</td><td>" + r.data[i].orderid + "</td><td>" + r.data[i].custom.customname + "</td><td>" +r.data[i].custom.telephone+ "</td><td>"+getFormtTime(r.data[i].ordertime,false)+"</td><td>"+r.data[i].ordermoney+"</td><td>"+r.data[i].users1.uname+"</td><td>审核通过</td><td>"+r.data[i].users2.uname+"</td><td>"+getFormtTime(r.data[i].chectime,false)+"</td><td>\n" +
                                        "          \t<a href=\"javascript:void(0)\" class=\"tablelink\">查看详情</a>\n" +
                                        "            <a href='../../storage/delivery/deliveryView.html' class='tablelink'>出库详情</a>\n" +
                                        "          </td></tr>"
                                }else if(r.data[i].status=="3"){
                                    t += "<tr> <td>" + r.data[i].rownum + "</td><td>" + r.data[i].orderid + "</td><td>" + r.data[i].custom.customname + "</td><td>" +r.data[i].custom.telephone+ "</td><td>"+getFormtTime(r.data[i].ordertime,false)+"</td><td>"+r.data[i].ordermoney+"</td><td>"+r.data[i].users1.uname+"</td><td>审核不通过</td><td>"+r.data[i].users2.uname+"</td><td>"+getFormtTime(r.data[i].chectime,false)+"</td><td>\n" +
                                        "            <a href=\"javascript:void(0)\" class=\"tablelink\">修改</a>\n" +
                                        "            <a href='javascript:void(0);' class='tablelink' onclick='examinetipOpen()'>提交审核</a>\n" +
                                        "          </td></tr>"
                                }
                            }
                            $(".tablelist").html(t)
                            // var pagenum = document.getElementById("pagenum");
                            $("#pagenum").html(r.pageNum)
                            // var totalrows = document.getElementById("totalrows");
                            // totalrows.innerHTML=r.totalRows
                            $("#totalrows").html(r.totalRows)

                            $(".tablelink").click(function() {

                                var text = $(this).text();
                                var orderid = $(this).parents("tr")[0].children[0].innerHTML
                                if (text == "查看详情") {
                                    window.location.href = "/orde/queryOneOrde/" + orderid
                                } else if (text == "修改") {
                                    window.location.href = "/orde/updateMarketCustom/" + orderid
                                } else if (text == "删除") {

                                } else if (text == "提交审核") {

                                } else if (text == "出库详情") {

                                }
                            })
                        }
                    })
                }
            })

            $("#xiayiye").click(function () {
                if (pagenum.innerHTML < r.totalPage) {
                    pagenum.innerHTML = Number(pagenum.innerHTML) + 1
                } else {
                    alert("已经是最后一页了")
                }

                var n = pagenum.innerHTML
                if (n <= r.totalPage) {
                    $.ajax({
                        type: "post",
                        url: "/orde/PageOrde",
                        data: {pageNum: n},
                        dataType: "json",
                        success: function (r) {
                            var t="<tr>\n" +
                                "          <th>序号</th>\n" +
                                "          <th>订单编号</th>\n" +
                                "          <th>客户姓名</th>\n" +
                                "          <th>联系电话</th>\n" +
                                "          <th>订购时间</th>\n" +
                                "          <th>金额</th>\n" +
                                "          <th>操作人</th>\n" +
                                "          <th>审核状态</th>\n" +
                                "          <th>审核人</th>\n" +
                                "          <th>审核时间</th>\n" +
                                "          <th>操作</th>\n" +
                                "        </tr>"
                            for (var i=0;i<r.data.length;i++){
                                if (r.data[i].status=="0"){
                                    t += "<tr> <td>" + r.data[i].rownum + "</td><td>" + r.data[i].orderid + "</td><td>" + r.data[i].custom.customname + "</td><td>" +r.data[i].custom.telephone+ "</td><td>"+getFormtTime(r.data[i].ordertime,false)+"</td><td>"+r.data[i].ordermoney+"</td><td>"+r.data[i].users1.uname+"</td><td>未审核</td><td>"+r.data[i].users2.uname+"</td><td>"+getFormtTime(r.data[i].chectime,false)+"</td><td>\n" +
                                        "          \t<a href=\"javascript:void(0)\" class=\"tablelink\">查看详情</a>\n" +
                                        "            <a href=\"javascript:void(0)\" class=\"tablelink\">修改</a>\n" +
                                        "            <a href='javascript:void(0);' class='tablelink' onclick='deltipOpen()'>删除</a>\n" +
                                        "            <a href='javascript:void(0);' class='tablelink' onclick='examinetipOpen()'>提交审核</a>\n" +
                                        "          </td></tr>"
                                }else if(r.data[i].status=="1"){
                                    t += "<tr> <td>" + r.data[i].rownum + "</td><td>" + r.data[i].orderid + "</td><td>" + r.data[i].custom.customname + "</td><td>" +r.data[i].custom.telephone+ "</td><td>"+getFormtTime(r.data[i].ordertime,false)+"</td><td>"+r.data[i].ordermoney+"</td><td>"+r.data[i].users1.uname+"</td><td>审核中</td><td>"+r.data[i].users2.uname+"</td><td>"+getFormtTime(r.data[i].chectime,false)+"</td><td>\n" +
                                        "          \t<a href=\"javascript:void(0)\" class=\"tablelink\">查看详情</a>\n" +
                                        "          </td></tr>"
                                }else if(r.data[i].status=="2"){
                                    t += "<tr> <td>" + r.data[i].rownum + "</td><td>" + r.data[i].orderid + "</td><td>" + r.data[i].custom.customname + "</td><td>" +r.data[i].custom.telephone+ "</td><td>"+getFormtTime(r.data[i].ordertime,false)+"</td><td>"+r.data[i].ordermoney+"</td><td>"+r.data[i].users1.uname+"</td><td>审核通过</td><td>"+r.data[i].users2.uname+"</td><td>"+getFormtTime(r.data[i].chectime,false)+"</td><td>\n" +
                                        "          \t<a href=\"javascript:void(0)\" class=\"tablelink\">查看详情</a>\n" +
                                        "            <a href='../../storage/delivery/deliveryView.html' class='tablelink'>出库详情</a>\n" +
                                        "          </td></tr>"
                                }else if(r.data[i].status=="3"){
                                    t += "<tr> <td>" + r.data[i].rownum + "</td><td>" + r.data[i].orderid + "</td><td>" + r.data[i].custom.customname + "</td><td>" +r.data[i].custom.telephone+ "</td><td>"+getFormtTime(r.data[i].ordertime,false)+"</td><td>"+r.data[i].ordermoney+"</td><td>"+r.data[i].users1.uname+"</td><td>审核不通过</td><td>"+r.data[i].users2.uname+"</td><td>"+getFormtTime(r.data[i].chectime,false)+"</td><td>\n" +
                                        "            <a href=\"javascript:void(0)\" class=\"tablelink\">修改</a>\n" +
                                        "            <a href='javascript:void(0);' class='tablelink' onclick='examinetipOpen()'>提交审核</a>\n" +
                                        "          </td></tr>"
                                }
                            }
                            $(".tablelist").html(t)
                            // var pagenum = document.getElementById("pagenum");
                            $("#pagenum").html(r.pageNum)
                            // var totalrows = document.getElementById("totalrows");
                            // totalrows.innerHTML=r.totalRows
                            $("#totalrows").html(r.totalRows)

                            $(".tablelink").click(function() {

                                var text = $(this).text();
                                var orderid = $(this).parents("tr")[0].children[0].innerHTML
                                if (text == "查看详情") {
                                    window.location.href = "/orde/queryOneOrde/" + orderid
                                } else if (text == "修改") {
                                    window.location.href = "/orde/updateMarketCustom/" + orderid
                                } else if (text == "删除") {

                                } else if (text == "提交审核") {

                                } else if (text == "出库详情") {

                                }
                            })
                        }
                    })
                }
            })

        }
    }
})


$("#check").click(function () {
    var orderNum = $("#orderNum").val();
    var customName = $("#customName").val();
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var startMoney = $("#startMoney").val();
    var endMoney = $("#endMoney").val();
    var shenhe = $("#shenhe option:selected").val();
    $.ajax({
        type: "post",
        url: "/orde/queryOrdeByCondition",
        data: {orderid: orderNum,customname:customName,ordertimeStart:startTime,ordertimeEnd:endTime,ordermoneyStart:startMoney,ordermoneyEnd:endMoney,status:shenhe},
        dataType: "json",
        success: function (r) {
            if (r!="null"){
                var t="<tr>\n" +
                    "          <th>序号</th>\n" +
                    "          <th>订单编号</th>\n" +
                    "          <th>客户姓名</th>\n" +
                    "          <th>联系电话</th>\n" +
                    "          <th>订购时间</th>\n" +
                    "          <th>金额</th>\n" +
                    "          <th>操作人</th>\n" +
                    "          <th>审核状态</th>\n" +
                    "          <th>审核人</th>\n" +
                    "          <th>审核时间</th>\n" +
                    "          <th>操作</th>\n" +
                    "        </tr>"
                for (var i=0;i<r.length;i++){
                    if (r[i].status=="0"){
                        t += "<tr> <td>" + r[i].rownum + "</td><td>" + r[i].orderid + "</td><td>" + r[i].custom.customname + "</td><td>" +r[i].custom.telephone+ "</td><td>"+getFormtTime(r[i].ordertime,false)+"</td><td>"+r[i].ordermoney+"</td><td>"+r[i].users1.uname+"</td><td>未审核</td><td>"+r[i].users2.uname+"</td><td>"+getFormtTime(r[i].chectime,false)+"</td><td>\n" +
                            "          \t<a href=\"javascript:void(0)\" class=\"tablelink\">查看详情</a>\n" +
                            "            <a href=\"javascript:void(0)\" class=\"tablelink\">修改</a>\n" +
                            "            <a href='javascript:void(0);' class='tablelink' onclick='deltipOpen()'>删除</a>\n" +
                            "            <a href='javascript:void(0);' class='tablelink' onclick='examinetipOpen()'>提交审核</a>\n" +
                            "          </td></tr>"
                    }else if(r[i].status=="1"){
                        t += "<tr> <td>" + r[i].rownum + "</td><td>" + r[i].orderid + "</td><td>" + r[i].custom.customname + "</td><td>" +r[i].custom.telephone+ "</td><td>"+getFormtTime(r[i].ordertime,false)+"</td><td>"+r[i].ordermoney+"</td><td>"+r[i].users1.uname+"</td><td>审核中</td><td>"+r[i].users2.uname+"</td><td>"+getFormtTime(r[i].chectime,false)+"</td><td>\n" +
                            "          \t<a href=\"javascript:void(0)\" class=\"tablelink\">查看详情</a>\n" +
                            "          </td></tr>"
                    }else if(r[i].status=="2"){
                        t += "<tr> <td>" + r[i].rownum + "</td><td>" + r[i].orderid + "</td><td>" + r[i].custom.customname + "</td><td>" +r[i].custom.telephone+ "</td><td>"+getFormtTime(r[i].ordertime,false)+"</td><td>"+r[i].ordermoney+"</td><td>"+r[i].users1.uname+"</td><td>审核通过</td><td>"+r[i].users2.uname+"</td><td>"+getFormtTime(r[i].chectime,false)+"</td><td>\n" +
                            "          \t<a href=\"javascript:void(0)\" class=\"tablelink\">查看详情</a>\n" +
                            "            <a href='../../storage/delivery/deliveryView.html' class='tablelink'>出库详情</a>\n" +
                            "          </td></tr>"
                    }else if(r[i].status=="3"){
                        t += "<tr> <td>" + r[i].rownum + "</td><td>" + r[i].orderid + "</td><td>" + r[i].custom.customname + "</td><td>" +r[i].custom.telephone+ "</td><td>"+getFormtTime(r[i].ordertime,false)+"</td><td>"+r[i].ordermoney+"</td><td>"+r[i].users1.uname+"</td><td>审核不通过</td><td>"+r[i].users2.uname+"</td><td>"+getFormtTime(r[i].chectime,false)+"</td><td>\n" +
                            "            <a href=\"javascript:void(0)\" class=\"tablelink\">修改</a>\n" +
                            "            <a href='javascript:void(0);' class='tablelink' onclick='examinetipOpen()'>提交审核</a>\n" +
                            "          </td></tr>"
                    }
                }
                $(".tablelist").html(t)
                // var pagenum = document.getElementById("pagenum");
                $("#pagenum").html(r.pageNum)
                // var totalrows = document.getElementById("totalrows");
                // totalrows.innerHTML=r.totalRows
                $("#totalrows").html(r.totalRows)

                $(".tablelink").click(function() {

                    var text = $(this).text();
                    var orderid = $(this).parents("tr")[0].children[0].innerHTML
                    if (text == "查看详情") {
                        window.location.href = "/orde/queryOneOrde/" + orderid
                    } else if (text == "修改") {
                        window.location.href = "/orde/updateMarketCustom/" + orderid
                    } else if (text == "删除") {

                    } else if (text == "提交审核") {

                    } else if (text == "出库详情") {

                    }
                })
            }else {
                alert("没有这类人哦！")
            }
        }
    })
})

